"""
应用入口文件 - 专为生产环境设计

✅ 支持直接 uvicorn 启动
✅ 无缝部署到 Linux 服务器
✅ 完整的生命周期管理

启动命令:
uvicorn app:app --reload --port 9012
"""
import logging
from fastapi import FastAPI
from api.routes import router as api_router
from api.events import register_startup_event, register_shutdown_event

# 配置日志
logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
    datefmt="%Y-%m-%d %H:%M:%S"
)
logger = logging.getLogger("QuantSystem")

# 创建FastAPI应用
app = FastAPI(
    title="量化交易系统",
    version="2.0",
    description="专业级量化交易平台 - 精确策略控制 & 专业部署架构",
    docs_url="/docs",
    redoc_url="/redoc"
)

# 注册API路由
app.include_router(api_router, prefix="/api")

# 注册生命周期事件
register_startup_event(app)
register_shutdown_event(app)

@app.get("/", include_in_schema=False)
async def root():
    """健康检查端点"""
    return {
        "status": "running",
        "service": "quant-trading-system",
        "version": "2.0",
        "api_docs": "/docs"
    }

logger.info("✅ 应用入口初始化完成 - 准备接收请求")